package com.study.concurrentprogramming.practice;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class threadCommon {

    public static void main(String[] args) {
        int threadCount = 2;
        int loop = 200;
        ThreadSafe threadUnsafe = new ThreadSafe();
        for (int i = 0; i < threadCount; i++) {
            Thread thread = new Thread(() -> {
                for(int j=0; j < loop; j++) {
                    threadUnsafe.method();
                }
            }, "t" + i);
            thread.start();
        }
    }

    static class ThreadSafe {

        public void method() {
            List<String> arr = new ArrayList<>();
            addE(arr);
            removeE(arr);
        }

        private void addE(List<String> arr) {
            arr.add("1");
        }

        private void removeE(List<String> arr) {
            arr.remove(0);
        }
    }
}
